package adapter;

import java.text.SimpleDateFormat;
import java.util.List;

import com.wonyesoft.wuliu.R;

import javabeen.OrderListBeen;

import android.content.Context;
import android.database.DataSetObserver;
import android.graphics.Color;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

/**
 * * @author 作者 陈修园:
 * 
 * @date 创建时间：2015-5-20 上午10:36:28
 * @version 1.0
 * @parameter
 * @since
 * @return
 */
public class OrderListAdapter extends BaseAdapter {

	public List<OrderListBeen> CarOrder;
	private int xml;
	private Context context;
	private LayoutInflater inflater;

	// ImageMemoryCache imageMemoryCache;
	// private GetViewForRunnable getViewForRunnable;

	public OrderListAdapter(Context context, List<OrderListBeen> order_infos,
			int xml) {
		this.CarOrder = order_infos;
		this.xml = xml;
		this.context = context;
		if (this.context != null) {
			this.inflater = LayoutInflater.from(context);
		}

	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return CarOrder.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return CarOrder.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ViewHolder viewHolder;
		if (convertView == null) {
			convertView = inflater.inflate(xml, null);
			viewHolder = new ViewHolder();
			viewHolder.myorder_content_tab = (TextView) convertView
					.findViewById(R.id.myorder_content_tab);
			viewHolder.myorder_content_time = (TextView) convertView
					.findViewById(R.id.myorder_content_time);
			viewHolder.myorder_content_qitext = (TextView) convertView
					.findViewById(R.id.myorder_content_qitext);
			viewHolder.myorder_content_zhongtext = (TextView) convertView
					.findViewById(R.id.myorder_content_zhongtext);
			viewHolder.myorder_content_flowid=(TextView) convertView.findViewById(R.id.myorder_content_flowid);
			viewHolder.myorder_content_rmb = (TextView) convertView
					.findViewById(R.id.myorder_content_rmb);
			viewHolder.sdtoas = (TextView) convertView
					.findViewById(R.id.sdtoas);

			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		OrderListBeen data = CarOrder.get(position);
		if (data != null) {
			//if () {
//				viewHolder.myorder_content_flowid.setText(text);
//				viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
//						+ "¥");// (R.id.myorder_content_flowid);
		//	}
//			viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
//					+ "¥");// (R.id.myorder_content_flowid);
			viewHolder.myorder_content_time.setText(data.getOrderformdata()); // (R.id.myorder_content_tab);
			viewHolder.myorder_content_qitext.setText(data.getOrigin());// (R.id.myorder_content_zhongtext);
			viewHolder.myorder_content_zhongtext.setText(data.getDestination()); // (R.id.myorder_content_time);\\
			if (data.getState().equals("1")) {
				viewHolder.myorder_content_rmb.setText("待审核");
				viewHolder.myorder_content_flowid.setText("期望价格");
				viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
						+ "¥");
			}
			if (data.getState().equals("2")) {
				viewHolder.myorder_content_rmb.setText("待审核");
				viewHolder.myorder_content_flowid.setText("期望价格");
				viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
						+ "¥");
			}
			if (data.getState().equals("3")) {
				viewHolder.myorder_content_rmb.setText("议价中");
				viewHolder.myorder_content_flowid.setText("期望价格");
				viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
						+ "¥");
			}
			if (data.getState().equals("4")) {
				viewHolder.myorder_content_flowid.setText("最终价格");
				viewHolder.myorder_content_tab.setText("" + data.getFinalprice()
						+ "¥");
				viewHolder.myorder_content_rmb.setText("运送中");
			}
			if (data.getState().equals("5")) {
				viewHolder.myorder_content_flowid.setText("期望价格");
				viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
						+ "¥");
				viewHolder.myorder_content_rmb.setText("订单取消");
			}
			if (data.getState().equals("6")) {
				viewHolder.myorder_content_flowid.setText("最终价格");
				viewHolder.myorder_content_tab.setText("" + data.getFinalprice()
						+ "¥");
				viewHolder.myorder_content_rmb.setText("转单中");
			}
			if (data.getState().equals("7")) {
				viewHolder.myorder_content_flowid.setText("最终价格");
				viewHolder.myorder_content_tab.setText("" + data.getFinalprice()
						+ "¥");
				viewHolder.myorder_content_rmb.setText("已完成");
			}
			if (data.getState().equals("8")) {
				viewHolder.myorder_content_rmb.setText("订单取消");
				viewHolder.myorder_content_flowid.setText("期望价格");
				viewHolder.myorder_content_tab.setText("" + data.getExpectprice()
						+ "¥");
			}
			if (data.getState().equals("9")) {
				viewHolder.myorder_content_flowid.setText("最终价格");
				viewHolder.myorder_content_tab.setText("" + data.getFinalprice()
						+ "¥");
				viewHolder.myorder_content_rmb.setText("待确认");
			}
			if (data.getState().equals("0")) {
				viewHolder.myorder_content_flowid.setText("最终价格");
				viewHolder.myorder_content_tab.setText("" + data.getFinalprice()
						+ "¥");
				viewHolder.myorder_content_rmb.setText("司机再次确认中");
			}
			viewHolder.sdtoas.setText("途经地数目：" + (data.getDs())); // (R.id.myorder_content_qitext);
		}

		return convertView;
	}

	class ViewHolder {
		TextView myorder_content_tab; 
		TextView myorder_content_time; 
		TextView myorder_content_qitext; 
		TextView myorder_content_zhongtext; 
		TextView myorder_content_flowid;	
		TextView myorder_content_rmb; 
		TextView sdtoas; 
	}

	@Override
	public void unregisterDataSetObserver(DataSetObserver observer) {
		// TODO Auto-generated method stub
		if (observer != null) {
			super.unregisterDataSetObserver(observer);
		}

	}

}
